
<link rel="stylesheet" href="__PUBLIC__/yksui/css/zui.css" rel="stylesheet"/>
<style>
    .w120{width: 120px;}
</style>
<div class="" >
    <form  method="post" action="{:U('Inboundshipmentplan/savePickSku')}" onsubmit="return checkSubmit()">
        <div class="container">
            <div class="container-fluid">
                <h4 class="hide_ff">Shipmentid：{$shipmentId}
                </h4>
                <input type="hidden" name="shipmentId" value="{$shipmentId}">
                <input type="hidden" name="seller_id" value="{$seller_id}">
                <input type="hidden" name="site_id" value="{$site_id}">
                <input type="hidden" name="accountName" value="{$accountName}">
                <input type="hidden" name="shipmentPlanId" value="{$shipmentPlanId}">
                <table class="table table-striped table-hover" cellspacing="0" width="100%" >
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>SKU</th>
                        <th>是否出口退税</th>
                        <th>主体</th>
                        <th>需求数量</th>
                        <th>储位</th>
                        <th>可用数量</th>
                        <th>拣货数量</th>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name="skuDetail" id="val" key="number">
                        <tr class="pick-qty">
                            <td>{$number}</td>
                            <td class="sku">
                                <input type="hidden" name="sku[]" value="{$val.sku}">
                                <input type="hidden" name="fnsku[]" value="{$val.fnsku}">
                                <input type="hidden" name="{$val.fnsku}[detailId]" value="{$val.id}">
                                {$val.sku}
                            </td>
                            <td class="export_tax_rebate">
                                <input type="hidden" name="{$val.fnsku}[export_tax_rebate]" value="{$val.export_tax_rebate}">
                                <if condition="$val.export_tax_rebate eq 0">非<else />是</if>
                            </td>
                            <td class="enterpriseDominantsName">
                                <input type="hidden" name="{$val.fnsku}[enterpriseDominantsName]" value="{$val.enterpriseDominantsName}">
                                {$val.enterpriseDominantsName}
                            </td>
                            <td class="need-qty">
                                <input type="hidden" name="{$val.fnsku}[quantity]" value="{$val.quantity}">
                                {$val.quantity}
                            </td>
                            <td colspan="3">
                                <table class="table">
                                    <volist name="val.stock" id="skuStock" key="num">
                                        <tr class="qty_list">
                                            <td class="position">
                                                <input type="hidden" name="{$val.fnsku}[position][]" value="{$Think.lang.$key}">
                                                {$Think.lang.$key}
                                            </td>
                                            <td class="use-qty">
                                                <!--<input type="hidden" name="available_quantity{$num}[]" value="{$skuStock.available_quantity}">-->
                                                {$skuStock.available_quantity}
                                            </td>
                                            <td class="val-qty">
                                                <input type="text" name="{$val.fnsku}[advise_quantity][]" id="" class="form-control w120 " onblur="check_sum()" value="{$skuStock.advise_quantity}">
                                            </td>
                                        </tr>
                                    </volist>
                                </table>
                            </td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="text-center">
            <button type="submit"  class="btn btn-primary save_detail">确认</button>

        </div>
    </form>
</div>

<script type="text/javascript" src="__PUBLIC__/javascripts/admin/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/javascripts/admin/WdatePicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>
<script type="application/javascript">
    //拣货单确认检验
    function checkSubmit() {
        var msg = '';
        var success = '';
        $('.pick-qty').each(function () {
            var need= parseInt($(this).children('.need-qty').text());
            var sku= $(this).children('.sku').text();
            var val = 0;
            //检验储位的可用数量是否小于拣货数量
            $(this).find('.qty_list').each(function () {
                var position = $(this).find('.position').text();
                if(parseInt($(this).find('.use-qty').text())<parseInt($(this).find('.val-qty').find('input').val())){
                    msg += sku+"的"+position+"储位的拣货数量大于可用数量<br>";
                }
            });
            $(this).find('.val-qty').each(function () {
                val += parseInt($(this).find('input').val())
            })
            //检验sku需求数量是否小于拣货数量
            if(need < val){
                msg += sku+"拣货数量大于需求数量<br>";
            }
            if(need > val){
                msg = sku+"拣货数量小于需求数量<br>";
            }
        });
        if(msg!=''){
            layer.msg(msg, {icon: 5});
            return false;
        }
        layer.load();
        return true;
    }

    /*$(document).ready(function () {
        $('.use-qty').each(function (i) {
            if($(this).siblings('.val-qty').find('input').val() > parseInt($(this).text())){
                $(this).siblings('.val-qty').find('input').val(parseInt($(this).text()));
            }
            if($(this).siblings('.val-qty').find('input').val()> parseInt($(this).text())){
                $(this).siblings('.val-qty').find('input').val($(this).siblings('.val-qty').find('input').val());
            }
        });
    });*/

    //检验数据
    function check_sum() {
        var msg = '';
        var statu = 0;
        var success = '';
        $('.pick-qty').each(function () {
            var need= parseInt($(this).children('.need-qty').text());
            var sku= $(this).children('.sku').text();
            var val = 0;
            //检验储位的可用数量是否小于拣货数量
            $(this).find('.qty_list').each(function () {
                var position = $(this).find('.position').text();
                if(parseInt($(this).find('.use-qty').text())<parseInt($(this).find('.val-qty').find('input').val())){
                    msg += sku+"的"+position+"储位的拣货数量大于可用数量\n";
                }
            });
            $(this).find('.val-qty').each(function () {
                val += parseInt($(this).find('input').val())
            })
            //检验sku需求数量是否小于拣货数量
            if(need < val){
                msg += sku+"拣货数量大于需求数量\n";
            }
            if(need > val){
                msg = sku+"拣货数量小于需求数量，\n";;
            }
        });
        if(msg!=''){
            layer.msg(msg, {icon: 5});
            return;
        }
    }
</script>


